package com.google.android.daca.util;

import java.util.ArrayList;
import java.util.List;

import com.google.android.daca.types.Option;
import com.google.android.daca.types.Participant;
import com.google.android.daca.types.Poll;

public class PollResultsUtil {
	public static List<OptionAggregate> getOptionAggregates(Poll poll) {
		List<OptionAggregate> result = new ArrayList<OptionAggregate>();
		List<Participant> participants = poll.getParticipants();
		List<Option> options = poll.getOptions();
		for (int i = 0; i < options.size(); ++i) {
			Option option = options.get(i);
			int yesCount = 0;
			for (Participant participant : participants) {
				if (participant.getPreferences().get(i) == 1) {
					++yesCount;
				}
			}
			OptionAggregate aggregate = new OptionAggregate(option.getValue(), 
															yesCount,
															participants.size() - yesCount);
			result.add(aggregate);
		}
		return result;
		
	}
	
	
}
